#include<stdio.h>
#include<stddef.h>
// *运算符 取值/表示指针
void increment(int* p) {
  *p = *p + 1;
}

int main(void) {
	//指向 int 类型的指针
	int* intPtr;
	//不算错误的写法
	int *intPtr1;
	int * intPtr2;
	int* intPtr3;
	// 一行多个指针
	int * foo, * bar;
	// 指针的指正
	int** foo1;
	
  // &运算符 取出内存地址
  int x = 1;
  increment(&x);
  printf("x's address is %p\n", &x);
  // 指针初始化
  // 注意地址是随机的,不要读取
  int* p;
  // *p = 1; 错误,
  // 正确的做法是让指针指向一个指定的地址
  int* p1;
  int i;
  p1 = &i;
  // 可以将指针初始化为 Null
  int* p2 = NULL;


  // 指针的运算
  short* j;
  j = (short*)0x1234;
  printf("j's old address %p\n", j);
  j = j + 1;
  printf("j's new address %p\n", j);
  // 指针只能与整数值加减
  unsigned short* j0;
  unsigned short* k0;
  // x = j1 + k1 非法
  short* j1;
  short* j2;

  j1 = (short*)0x1234;
  j2 = (short*)0x1236;
  // 相减是为了计算内存地址之间的距离
  ptrdiff_t dist = j2 - j1;
  printf("%d\n", dist); // 1
  // 比较运算
  const int j3 = &j1 > &j2;
  printf("%d\n", j3);
  return 0;
}

